// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.QueryDsl;

public sealed partial class SpanOrQuery
{
	/// <summary>
	/// <para>Floating point number used to decrease or increase the relevance scores of the query.<br/>Boost values are relative to the default value of 1.0.<br/>A boost value between 0 and 1.0 decreases the relevance score.<br/>A value greater than 1.0 increases the relevance score.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("boost")]
	public float? Boost { get; set; }

	/// <summary>
	/// <para>Array of one or more other span type queries.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("clauses")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQuery> Clauses { get; set; }
	[JsonInclude, JsonPropertyName("_name")]
	public string? QueryName { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query(SpanOrQuery spanOrQuery) => Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query.SpanOr(spanOrQuery);
	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQuery(SpanOrQuery spanOrQuery) => Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQuery.SpanOr(spanOrQuery);
}

public sealed partial class SpanOrQueryDescriptor<TDocument> : SerializableDescriptor<SpanOrQueryDescriptor<TDocument>>
{
	internal SpanOrQueryDescriptor(Action<SpanOrQueryDescriptor<TDocument>> configure) => configure.Invoke(this);

	public SpanOrQueryDescriptor() : base()
	{
	}

	private float? BoostValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQuery> ClausesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor<TDocument> ClausesDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor<TDocument>> ClausesDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor<TDocument>>[] ClausesDescriptorActions { get; set; }
	private string? QueryNameValue { get; set; }

	/// <summary>
	/// <para>Floating point number used to decrease or increase the relevance scores of the query.<br/>Boost values are relative to the default value of 1.0.<br/>A boost value between 0 and 1.0 decreases the relevance score.<br/>A value greater than 1.0 increases the relevance score.</para>
	/// </summary>
	public SpanOrQueryDescriptor<TDocument> Boost(float? boost)
	{
		BoostValue = boost;
		return Self;
	}

	/// <summary>
	/// <para>Array of one or more other span type queries.</para>
	/// </summary>
	public SpanOrQueryDescriptor<TDocument> Clauses(ICollection<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQuery> clauses)
	{
		ClausesDescriptor = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = null;
		ClausesValue = clauses;
		return Self;
	}

	public SpanOrQueryDescriptor<TDocument> Clauses(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor<TDocument> descriptor)
	{
		ClausesValue = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = null;
		ClausesDescriptor = descriptor;
		return Self;
	}

	public SpanOrQueryDescriptor<TDocument> Clauses(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor<TDocument>> configure)
	{
		ClausesValue = null;
		ClausesDescriptor = null;
		ClausesDescriptorActions = null;
		ClausesDescriptorAction = configure;
		return Self;
	}

	public SpanOrQueryDescriptor<TDocument> Clauses(params Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor<TDocument>>[] configure)
	{
		ClausesValue = null;
		ClausesDescriptor = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = configure;
		return Self;
	}

	public SpanOrQueryDescriptor<TDocument> QueryName(string? queryName)
	{
		QueryNameValue = queryName;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		if (ClausesDescriptor is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, ClausesDescriptor, options);
			writer.WriteEndArray();
		}
		else if (ClausesDescriptorAction is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor<TDocument>(ClausesDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (ClausesDescriptorActions is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			foreach (var action in ClausesDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor<TDocument>(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("clauses");
			JsonSerializer.Serialize(writer, ClausesValue, options);
		}

		if (!string.IsNullOrEmpty(QueryNameValue))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(QueryNameValue);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class SpanOrQueryDescriptor : SerializableDescriptor<SpanOrQueryDescriptor>
{
	internal SpanOrQueryDescriptor(Action<SpanOrQueryDescriptor> configure) => configure.Invoke(this);

	public SpanOrQueryDescriptor() : base()
	{
	}

	private float? BoostValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQuery> ClausesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor ClausesDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor> ClausesDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor>[] ClausesDescriptorActions { get; set; }
	private string? QueryNameValue { get; set; }

	/// <summary>
	/// <para>Floating point number used to decrease or increase the relevance scores of the query.<br/>Boost values are relative to the default value of 1.0.<br/>A boost value between 0 and 1.0 decreases the relevance score.<br/>A value greater than 1.0 increases the relevance score.</para>
	/// </summary>
	public SpanOrQueryDescriptor Boost(float? boost)
	{
		BoostValue = boost;
		return Self;
	}

	/// <summary>
	/// <para>Array of one or more other span type queries.</para>
	/// </summary>
	public SpanOrQueryDescriptor Clauses(ICollection<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQuery> clauses)
	{
		ClausesDescriptor = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = null;
		ClausesValue = clauses;
		return Self;
	}

	public SpanOrQueryDescriptor Clauses(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor descriptor)
	{
		ClausesValue = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = null;
		ClausesDescriptor = descriptor;
		return Self;
	}

	public SpanOrQueryDescriptor Clauses(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor> configure)
	{
		ClausesValue = null;
		ClausesDescriptor = null;
		ClausesDescriptorActions = null;
		ClausesDescriptorAction = configure;
		return Self;
	}

	public SpanOrQueryDescriptor Clauses(params Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor>[] configure)
	{
		ClausesValue = null;
		ClausesDescriptor = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = configure;
		return Self;
	}

	public SpanOrQueryDescriptor QueryName(string? queryName)
	{
		QueryNameValue = queryName;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		if (ClausesDescriptor is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, ClausesDescriptor, options);
			writer.WriteEndArray();
		}
		else if (ClausesDescriptorAction is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor(ClausesDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (ClausesDescriptorActions is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			foreach (var action in ClausesDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.SpanQueryDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("clauses");
			JsonSerializer.Serialize(writer, ClausesValue, options);
		}

		if (!string.IsNullOrEmpty(QueryNameValue))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(QueryNameValue);
		}

		writer.WriteEndObject();
	}
}